package com.genexususa.eo.bing.data.wsSubclasses;

import com.genexususa.eo.bing.CampaignManagementServiceClasses.Step;
import com.genexususa.eo.bing.CampaignManagementServiceClasses.StepType;
import com.genexususa.eo.bing.data.GxItemException;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

public class GxStep extends Step {
    private long gxId;

    public GxStep(Element element) throws IllegalArgumentException, GxItemException {
        if (element.getElementsByTagName("GxStepId").getLength() > 0 &&
            element.getElementsByTagName("GxStepId").item(0).getChildNodes().getLength() > 0 &&
            Long.valueOf(((Node)element.getElementsByTagName("GxStepId").item(0).getChildNodes().item(0)).getNodeValue()) != 0) {
            this.gxId = Long.valueOf(((Node)element.getElementsByTagName("GxStepId").item(0).getChildNodes().item(0)).getNodeValue());
        } else {
            throw new GxItemException("Missing external Step id");
        }
        if (element.getElementsByTagName("BingStepId").getLength() > 0 &&
            element.getElementsByTagName("BingStepId").item(0).getChildNodes().getLength() > 0 &&
            Long.valueOf(((Node)element.getElementsByTagName("BingStepId").item(0).getChildNodes().item(0)).getNodeValue()) != 0) {
            this.setId(Long.valueOf(((Node) element.getElementsByTagName("BingStepId").item(0).getChildNodes().item(0)).getNodeValue()));
        }
        if (element.getElementsByTagName("Name").getLength() > 0 &&
            element.getElementsByTagName("Name").item(0).getChildNodes().getLength() > 0) {
            this.setName(((Node) element.getElementsByTagName("Name").item(0).getChildNodes().item(0)).getNodeValue());
        }
        if (element.getElementsByTagName("PositionNumber").getLength() > 0 &&
            element.getElementsByTagName("PositionNumber").item(0).getChildNodes().getLength() > 0) {
            this.setPositionNumber(Integer.valueOf(((Node) element.getElementsByTagName("PositionNumber").item(0).getChildNodes().item(0)).getNodeValue()));
        }
        if (element.getElementsByTagName("Script").getLength() > 0 &&
            element.getElementsByTagName("Script").item(0).getChildNodes().getLength() > 0) {
            this.setScript(((Node) element.getElementsByTagName("Script").item(0).getChildNodes().item(0)).getNodeValue());
        }
        if (element.getElementsByTagName("Type").getLength() > 0 &&
            element.getElementsByTagName("Type").item(0).getChildNodes().getLength() > 0) {
            this.setType(StepType.fromString(((Node) element.getElementsByTagName("Type").item(0).getChildNodes().item(0)).getNodeValue()));
        }
    }

    public long getGxId() {
        return gxId;
    }

    public void setGxId(long gxId) {
        this.gxId = gxId;
    }
}
